#!/bin/bash

# 设置变量
IMAGE_NAME="my-vue-app"
CONTAINER_NAME="my-vue-app-c"
PORT="80:80"
DOCKERFILE_PATH="."

# 停止并删除旧的容器
echo "Stopping and removing old container..."
docker stop $CONTAINER_NAME > /dev/null 2>&1
docker rm $CONTAINER_NAME > /dev/null 2>&1

# 构建新的 Docker 镜像
echo "Building new Docker image..."
docker build --no-cache -t $IMAGE_NAME $DOCKERFILE_PATH

# 运行新的 Docker 容器
echo "Running new Docker container..."
docker run -d --restart always -p $PORT --name $CONTAINER_NAME $IMAGE_NAME

# 检查容器是否成功启动
if [ $? -eq 0 ]; then
    echo "Docker container '$CONTAINER_NAME' is up and running!"
else
    echo "Failed to start the Docker container. Check logs for details."
fi
